package com.superman.supermarket.client.view.addredit;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.supermarket.client.widget.button.TextButton;
import com.superman.supermarket.client.widget.header.PageHeader;
import com.superman.supermarket.client.widget.input.type.AreaSelectInput;
import com.superman.supermarket.client.widget.input.type.DetailAddressInput;
import com.superman.supermarket.client.widget.input.type.ReceiverNameInput;
import com.superman.supermarket.client.widget.input.type.TelInput;

/**
 * 地址编辑/新建ui实现类
 * 
 * @author superman
 * @version 2018年8月2日下午5:00:17
 */
public class AddrEditViewImpl extends Composite implements AddrEditView {

	interface AddrEditViewImplUiBinder extends UiBinder<Widget, AddrEditViewImpl> {
	}

	private static AddrEditViewImplUiBinder uiBinder = GWT.create(AddrEditViewImplUiBinder.class);

	@UiField
	DetailAddressInput addrinput;

	@UiField
	AreaSelectInput areainput;
	@UiField
	ReceiverNameInput nameinput;
	@UiField
	PageHeader pageheader;
	private AddrEditViewPresenter presenter;
	@UiField
	TextButton save;
	@UiField
	TelInput telinput;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月2日 下午10:22:48
	 */
	public AddrEditViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

	@UiHandler("save")
	void save(ClickEvent event) {
		if (nameinput.validInput() && telinput.validInput() && areainput.validInput() && addrinput.validInput()) {
			presenter.save(nameinput.getValue(), telinput.getValue(), areainput.getAreaCode(), areainput.getValue(), addrinput.getValue());
		}
	}

	@Override
	public void setDefaultAddrInfo(String receivername, String telno, String areacode, String area, String address) {
		nameinput.setValue(receivername);
		telinput.setValue(telno);
		areainput.setAreaCode(areacode);
		areainput.setValue(area);
		addrinput.setValue(address);
	}

	@Override
	public void setHeaderText(String text) {
		pageheader.setText(text);
	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		this.presenter = (AddrEditViewPresenter) presenter;
	}

}
